package com.slw.caiji.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.slw.caiji.Vo.params.PageParams;
import com.slw.caiji.dto.SysIcon;
import com.slw.caiji.dto.SysMenu;
import com.slw.caiji.mapper.SysIconMapper;
import com.slw.caiji.service.SysIconService;
import com.slw.caiji.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysIconServiceImpl implements SysIconService {

    @Autowired
    private SysIconMapper sysIconMapper;

    @Override
    public Result getSysIconList(PageParams pageParams) {
        final Page<SysIcon> objectPage = new Page<>(pageParams.getCurrent(), pageParams.getPageSize());
        final IPage<SysIcon> sysUserIPage = sysIconMapper.listSysIcon(objectPage);
        return Result.success(sysUserIPage);
    }

    @Override
    public Result addIcon(SysIcon sysIcon) {
        final SysIcon sysIcon1 = new SysIcon();
        sysIcon1.setName(sysIcon.getName());
        sysIcon1.setUrl(sysIcon.getUrl());
        return Result.success(sysIconMapper.insert(sysIcon1));
    }

    @Override
    public Result delIcon(String ids) {
        final String[] split = ids.split(",");
        for (String s : split) {
            sysIconMapper.deleteById(s);
        }
        return Result.success(1);
    }
}
